local fn = vim.fn
-- local mirror = "https://ghproxy.com/https://github.com/"
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
    packer_bootstrap =
        fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
    vim.cmd([[packadd packer.nvim]])
end

-- require('packer').init({
--     git = {
--         default_url_format = mirror .. '%s'
--     }
-- })

return require("packer").startup({
    function(use)
        -- My plugins here
        -- use 'foo1/bar1.nvim'
        -- use 'foo2/bar2.nvim'
        use("wbthomason/packer.nvim")
        use("easymotion/vim-easymotion")
        -- 主题
        use("folke/tokyonight.nvim")

        -- 侧边栏
        use({ "kyazdani42/nvim-tree.lua", requires = "kyazdani42/nvim-web-devicons" })

        -- 注释
        use("terrortylor/nvim-comment")
        -- Automatically set up your configuration after cloning packer.nvim
        -- Put this at the end after all plugins
        -- bufferline 标签
        use({ "akinsho/bufferline.nvim", requires = { "kyazdani42/nvim-web-devicons", "moll/vim-bbye" } })
        -- 底栏
        use({ "nvim-lualine/lualine.nvim", requires = { "kyazdani42/nvim-web-devicons" } })
        use("arkav/lualine-lsp-progress")

        -- 模糊搜索文件
        use({ "nvim-telescope/telescope.nvim", requires = { "nvim-lua/plenary.nvim" } })
        use("nvim-telescope/telescope-media-files.nvim")
        use("nvim-telescope/telescope-file-browser.nvim")
        -- use 'anekos/telescope-locate'
        use("LinArcX/telescope-env.nvim")

        use({ "glepnir/dashboard-nvim", requires = { "nvim-tree/nvim-web-devicons" } })

        -- project
        use("ahmedkhalf/project.nvim")

        --解决python缩进问题
        use({ "yioneko/nvim-yati", requires = "nvim-treesitter/nvim-treesitter" })
        use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" })

        use("williamboman/nvim-lsp-installer")
        -- Lspconfig
        use({ "neovim/nvim-lspconfig" })

        -- lsp 增加函数参数文档显示
        use("ray-x/lsp_signature.nvim")

        use("windwp/nvim-autopairs")
        -- 补全引擎
        use("hrsh7th/nvim-cmp")
        -- snippet 引擎
        use("hrsh7th/vim-vsnip")
        -- 补全源
        use("hrsh7th/cmp-vsnip")
        use("hrsh7th/cmp-nvim-lsp") -- { name = nvim_lsp }
        use("hrsh7th/cmp-buffer") -- { name = 'buffer' },
        use("hrsh7th/cmp-path") -- { name = 'path' }
        use("hrsh7th/cmp-cmdline") -- { name = 'cmdline' }

        -- 常见编程语言代码段
        use("rafamadriz/friendly-snippets")

        -- ui
        use("onsails/lspkind-nvim")

        use("lukas-reineke/indent-blankline.nvim")

        use("tami5/lspsaga.nvim")

        use({ "jose-elias-alvarez/null-ls.nvim", requires = "nvim-lua/plenary.nvim" })

        use("folke/which-key.nvim")
        use("mfussenegger/nvim-dap")
        use("ravenxrz/DAPInstall.nvim")
        use("theHamsta/nvim-dap-virtual-text")
        use("rcarriga/nvim-dap-ui")
        use("nvim-telescope/telescope-dap.nvim")
        use("jbyuki/one-small-step-for-vimkind")

        use({
            "kylechui/nvim-surround",
            tag = "*", -- Use for stability; omit to use `main` branch for the latest features
            config = function()
                require("nvim-surround").setup({
                    -- Configuration here, or leave empty to use defaults
                })
            end,
        })
        use({ "vladdoster/remember.nvim", config = [[ require('remember') ]] })
        use({
            "gabrielpoca/replacer.nvim",
            config = function()
                require("replacer")
                vim.api.nvim_set_keymap("n", "<leader>rr", ':lua require("replacer").run()<cr>', { silent = true })
            end,
        })
        use("dyng/ctrlsf.vim")

        use({
            "linux-cultist/venv-selector.nvim",
            dependencies = { "neovim/nvim-lspconfig", "nvim-telescope/telescope.nvim", "mfussenegger/nvim-dap-python" },
            config = function()
                require("venv-selector").setup()
            end,
            -- opts = {
            --     -- Your options go here
            --     -- name = "venv",
            --     -- auto_refresh = false
            -- },
            -- event = 'VeryLazy', -- Optional: needed only if you want to type `:VenvSelect` without a keymapping
            -- keys = {
            --     -- Keymap to open VenvSelector to pick a venv.
            --     { '<leader>vs', '<cmd>VenvSelect<cr>' },
            --     -- Keymap to retrieve the venv from a cache (the one previously used for the same project directory).
            --     { '<leader>vc', '<cmd>VenvSelectCached<cr>' },
            -- },
        })
        use({
            "abecodes/tabout.nvim",
            config = function()
                require("tabout").setup({
                    tabkey = "<Tab>", -- key to trigger tabout, set to an empty string to disable
                    backwards_tabkey = "<S-Tab>", -- key to trigger backwards tabout, set to an empty string to disable
                    act_as_tab = true, -- shift content if tab out is not possible
                    act_as_shift_tab = false, -- reverse shift content if tab out is not possible (if your keyboard/terminal supports <S-Tab>)
                    default_tab = "<C-t>", -- shift default action (only at the beginning of a line, otherwise <TAB> is used)
                    default_shift_tab = "<C-d>", -- reverse shift default action,
                    enable_backwards = true, -- well ...
                    completion = true, -- if the tabkey is used in a completion pum
                    tabouts = {
                        { open = "'", close = "'" },
                        { open = '"', close = '"' },
                        { open = "`", close = "`" },
                        { open = "(", close = ")" },
                        { open = "[", close = "]" },
                        { open = "{", close = "}" },
                    },
                    ignore_beginning = true, --[[ if the cursor is at the beginning of a filled element it will rather tab out than shift the content ]]
                    exclude = {}, -- tabout will ignore these filetypes
                })
            end,
            wants = { "nvim-treesitter" }, -- or require if not used so far
            after = { "nvim-cmp" }, -- if a completion plugin is using tabs load it before
        })
        -- use {
        --     'Joakker/lua-json5',
        --     run = './install.sh'
        -- }

        --use {
        --"mfussenegger/nvim-dap",
        --opt = true,
        --event = "BufReadPre",
        --module = { "dap" },
        --wants = { "nvim-dap-virtual-text", "DAPInstall.nvim", "nvim-dap-ui", "nvim-dap-python", "which-key.nvim" },
        --requires = {
        --"Pocco81/DAPInstall.nvim",
        --"theHamsta/nvim-dap-virtual-text",
        --"rcarriga/nvim-dap-ui",
        --"mfussenegger/nvim-dap-python",
        --"nvim-telescope/telescope-dap.nvim",
        --{ "jbyuki/one-small-step-for-vimkind", module = "osv" },
        --},
        --config = function()
        --require("plugin-config.dap").setup()
        --end,
        --}
        use("famiu/nvim-reload")
        if packer_bootstrap then
            require("packer").sync()
        end
    end,
    config = {
        max_jobs = 16,
    },
})
